

import React, { Component } from 'react'
import { connect } from 'react-redux';
import './login.less'
import { Input, Button, Checkbox } from 'antd';
import action from '../../store/Actions/index';
interface IProps {
  history: any,
  administratorReducer?: any,
  getLogin: any,
  setloginName: any,
  setloginPass: any,
  loginIndex?: any,
  jzpass?: any,
  setjzpass: any,
  setempty: any,
  loginObj?: any,
}
class index extends Component<IProps>{
  render() {

    return (
      <div className='login'>

        <div className="box">
          <div className="left">
            <h1>学员管理系统</h1>

            <div className='div2'>
              <p>振涛学生管理系统是一个面相学生的管理平台</p>
              <p>集录入、跟踪、升末班、缴费</p>
              <p>学习毕业一体化的系统</p>
            </div>
            {/* <div></div> */}
          </div>
          <div className="right">
            <div className='div1'>登录</div>
            <div className='btns'>
              <p><Input placeholder="请输入账号" value={this.props.administratorReducer.loginName} onChange={(e) => {
                this.props.setloginName(e.target.value)
              }} />
                {
                  this.props.administratorReducer.loginIndex == '03' ? <span className='span1'>没有该用户</span> : null
                }

              </p>
              <p><Input placeholder="请输入密码" type='password' value={this.props.administratorReducer.loginPass} onChange={(e) => {
                this.props.setloginPass(e.target.value)
              }} />
                {
                  this.props.administratorReducer.loginIndex == '02' ? <span className='span1'>密码错误</span> : null
                }

              </p>


            </div>
            <div className='pass'>

              <Checkbox checked={this.props.administratorReducer.jzpass} onChange={(e) => {
                this.props.setjzpass(!this.props.administratorReducer.jzpass)
              }}>记住密码</Checkbox >
              {/* <span>忘记密码?</span> */}


            </div>
            <div className='btns'>
              <Button type={this.props.administratorReducer.loginObj.type == '0' ? "primary" : null} onClick={() => {
                this.btnClick('0')
              }}>登陆</Button>
              <Button type={this.props.administratorReducer.loginObj.type == '1' ? "primary" : null} onClick={() => {
                this.btnClick('1')
              }}>市场部入口</Button>
              <Button type={this.props.administratorReducer.loginObj.type == '2' ? "primary" : null} onClick={() => {
                this.btnClick('2')
              }}>教务入口</Button>
              <Button type={this.props.administratorReducer.loginObj.type == '3' ? "primary" : null} onClick={() => {
                this.btnClick('3')
              }}>财务入口</Button>
            </div>
          </div>
        </div>

      </div>
    )
  }
  btnClick = async (msg) => {
    await this.props.getLogin({ loginName: this.props.administratorReducer.loginName, loginPass: this.props.administratorReducer.loginPass })

    if (this.props.administratorReducer.loginIndex == '01') {
     
      // console.log();
      if (this.props.administratorReducer.loginObj.type == msg) {
        if (msg == '0') {
          this.props.history.push({
            pathname: '/Home'
          })
          localStorage.setItem('token',JSON.stringify(this.props.administratorReducer.loginObj))
          if (!this.props.administratorReducer.jzpass) {
            this.props.setempty()//清空用户名，密码
          }
        } else if (msg == '1') {
          this.props.history.push({
            pathname: '/Marketing'
          })
          localStorage.setItem('token',JSON.stringify(this.props.administratorReducer.loginObj))
          if (!this.props.administratorReducer.jzpass) {
            this.props.setempty()//清空用户名，密码
          }
        } else if (msg == '2') {
          this.props.history.push({
            pathname: '/Educational'
          })
           localStorage.setItem('token',JSON.stringify(this.props.administratorReducer.loginObj))
          if (!this.props.administratorReducer.jzpass) {
            this.props.setempty()//清空用户名，密码
          }
        } else if (msg == '3') {
          this.props.history.push({
            pathname: '/Finance'
          })
          localStorage.setItem('token',JSON.stringify(this.props.administratorReducer.loginObj))
          if (!this.props.administratorReducer.jzpass) {
            this.props.setempty()//清空用户名，密码
          }
        }
      }



    }




  }
}

export default connect(state => state, action.administratorActions)(index);
